public class Transaction {
    private final int fromAccount;
    private final int toAccount;
    private final int amount;

    public Transaction(int fromAccount, int toAccount, int amount) {
        this.fromAccount = fromAccount;
        this.toAccount = toAccount;
        this.amount = amount;
    }

    public int getFromAccount() {
        return fromAccount;
    }

    public int getToAccount() {
        return toAccount;
    }

    public int getAmount() {
        return amount;
    }

    public static Transaction parse(String line) {
        String[] parts = line.split(" ");
        if (parts.length != 3) {
            return null;
        }
        try {
            int from = Integer.parseInt(parts[0]);
            int to = Integer.parseInt(parts[1]);
            int amount = Integer.parseInt(parts[2]);
            return new Transaction(from, to, amount);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Transaction getPoisonPill() {
        return new Transaction(-1, 0, 0);
    }

    public boolean isPoisonPill() {
        return fromAccount == -1;
    }
}